/*
 * All rights Reserved, Designed By cloudland Copyright(C) 2010-2014
 *
 * fileName:  SpringMvcExceptionHandler.java
 * author:  lei
 * Company:  Cloudland Studio
 * Createdate:  2013-9-15 下午2:47:29
 *   
 * Modification  History:
 *     Date           Author        Version        
 * -------------------------------------------
 * 2013-9-15          Lei            1.0        
 *
 * Why & What is modified:
 * 1.0: 文件创建
 */
package org.cloudland.web.multipart;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.cloudland.core.exception.IException;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.multiaction.NoSuchRequestHandlingMethodException;

 /**
 * <pre> 
 * TODO 请充分描述该类提供的作用, 或与其他类会有关联的使用。
 * 使用 {@link java.lang.Object#toString()}, 或者 {@link java.lang.Character Character} 等标签
 * </pre>
 * @ClassName  SpringMvcExceptionHandler
 * @author  lei
 * @version  %I%, %G%
 * @see  
 * @since   JDK1.6
 *
 */
public class SpringMvcExceptionHandler implements HandlerExceptionResolver {

	/**
     * LOGGER 日志对象
     */
    private static final Logger LOGGER = Logger.getLogger(SpringMvcExceptionHandler.class);

    /**
     * @param request
     * @param response
     * @param object
     * @param e
     * @return
     */
    public ModelAndView resolveException(HttpServletRequest request,
            HttpServletResponse response, Object object, Exception e)
    {
    	if (LOGGER.isDebugEnabled()) {
    		LOGGER.debug("Spring MVC unusually unified interface class");
    	}
    	
    	LOGGER.error(e.getMessage(), e);
    	
        String message = "程序处理发生未知错误，请与客服人员联系，寻求帮助。";
        if (e instanceof IException) {
            message = e.getMessage();
        } else if (e instanceof NoSuchRequestHandlingMethodException)
        {
            message = "请求的路径有问题。";
        }
        
        ModelAndView model = new ModelAndView("exception", "expMsg", message);
        return model;
    }
}
